import {IPageResponse, TInitFlag} from "@/common/common";
import {IEventType} from "@/common/model/EventType";
import _ from "lodash";
import {apiQueryAppEventTypesByRadar} from "@/common/apis/eventType";
import {makeAutoObservable, runInAction} from "mobx";
import {apiQueryEvents, IEventReq} from "@/common/apis/event";

class EventTypeStore {
  constructor() {
    makeAutoObservable(this)
  }

  loading = false;
  initialFlg: TInitFlag = "initial";
  eventTypes: IEventType[] = [];

  getEventTypes = async () => {
    if (!_.isEmpty(this.eventTypes)) {
      return this.eventTypes;
    }
    if (this.initialFlg !== "initial") {
      return;
    }
    this.initialFlg = "initialing";
    const res = await apiQueryAppEventTypesByRadar({application: "console"});
    runInAction(() => {
      if (res.code === 0) {
        this.eventTypes = res.data || []
      }
      this.initialFlg = "initialled";
    })
  }
}

export default new EventTypeStore()
